# class computer():
#     def __init__(self,a,b,c):
#         self.x=a
#         self.y=b
#         self.z=c
#     def add(self):
#         print(self.x+self.y)
#         return self.x+self.y
#     def div(self):
#         return self.z/self.x
# print('wishing低地区为父亲哦i俄方去哦')
#云商
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/')
#
# # driver.find_element_by_name("key").send_keys("拖鞋")
# driver.find_element_by_class_name("but1").send_keys("你有啥")
# driver.find_element_by_class_name("but2").click()

# driver.find_element_by_id("cart_num").click()
#云商后台
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php/admin/index/index')

# driver.find_element_by_id("username").send_keys("admin")
# driver.find_element_by_id("password").send_keys("admin")
# driver.find_element_by_name("submit").click()


# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('https://www.baidu.com/')
# driver.find_element_by_class_name("s_ipt").send_keys("你有啥")
# driver.find_element_by_class_name("soutu-btn").click()
# driver.find_element_by_class_name("upload-pic").click()


# driver.find_element_by_name("wd").send_keys("python")
# driver.find_element_by_name("tj_settingicon").click()
# driver.find_element_by_name("tj_login").click()
# driver.find_element_by_name("userName").send_keys("15229001690")
# driver.find_element_by_name("password").send_keys("asasas")

#driver.find_element_by_class_name('pass-button pass-button-submit').click()






# driver.find_element_by_id("kw").send_keys("我是谁")
# driver.find_element_by_id("su").click()


#
# c=computer(1,2,4)
# c.add()
# print(c.div())
# computer.aaa(1,2)

# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('https://www.baidu.com/')
# driver.find_element_by_class_name("s_ipt").send_keys("你有啥")
# driver.find_element_by_class_name("soutu-btn").click()
# driver.find_element_by_class_name("upload-pic").click()
# driver.find_element_by_id("cart_num").click()
# # 云商后台
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# driver.find_element_by_xpath("/html/body/div/div/div/div/a[1]").click()
#绝对路径
# driver.find_element_by_xpath("/html/body/div/div/div[2]/a[2]").click()
# driver.find_element_by_xpath("/html/body/div/div/div/div/form/input[1]").send_keys("11")
# driver.find_element_by_xpath("/html/body/div/div/div/div/form/input[2]").send_keys("22")
# 相对路径
# 1.Text文本
# driver.find_element_by_xpath('//a[text()="免费注册"]').click()
# driver.find_element_by_xpath('//a[text()="优惠券"]').click()
# 2.//标签[@属性=”属性值”]
# driver.find_element_by_xpath('//a[@class="header"][1]').click()
# driver.find_element_by_xpath('//a[@class=""][1]').click()
# 3.//*[@属性=”属性值”]
# driver.find_element_by_xpath('//*[@class="header"][2]').click()
# 4.//标签[@属性=’属性值’and@属性=’属性值’]   当一个属性不唯一时，用and加属性，加限制条件
# driver.maximize_window()
# driver.find_element_by_xpath("//input[@name='key'and@type='text'and@size='55']").send_keys("你有啥")

# 5.动态定位：属性的属性值只要包含所写的字符串就ok
# //标签[contains(@属性,’连续字符串（唯一）’)]
# driver.find_element_by_xpath("//form[contains(@action,'goods')]").click()
# 6.父级找子集
# //标签[@父级属性=”属性名”]/子集标签/子集属性
# driver.find_element_by_xpath("//h2/a[text()='运动健身']").click()
# driver.find_element_by_xpath("//div[@class=‘login’]/a[1])]").click()
# driver.find_element_by_xpath('//div/a[text()="美食"]').click()
# 7.从子集找父级
# //子集标签[属性=”属性值”]/..
# driver.find_element_by_xpath("//a[@class='header']/..").click()
# 8.从子集找祖父级
# //子集标签[属性=”属性值”]/../..
# driver.find_element_by_xpath("//a[@class='header']/../..").click()
# 9.找兄弟级（返回上一级在找）
# //标签[@属性=“属性值”]/../标签或  //标签[@属性=“属性值”]/../标签[@属性=“属性值”]
# driver.find_element_by_xpath("//div[@class='schbox']/../div[2]").click()
# 10.找叔叔级
# //子集标签[属性=”属性值”]/../../属性
# driver.find_element_by_xpath('//div/../../div[contains(@style,"block")]/../div[2]').click()
# 11.找祖父的兄弟级
# driver.find_element_by_xpath("//input[@class='but1']/../../../div[2]/a[1]").send_keys("哈哈")

# from selenium import webdriver
# driver = webdriver.Chrome()
# driver=webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# # 绝对路径
# driver.find_element_by_css_selector("html>body>div>div>div>div>a:nth-child(6)").click
# driver.find_element_by_css_selector("html>body>div>div>div>div>a:first-child").click
# driver.find_element_by_css_selector("html>body>div>div>div>div>a:last-child").click
# driver.find_element_by_css_selector('html>body>div>div>div>div>form>input[class="but1"]').send_keys("222")
# 相对路径
# id的属性值（只有id才可以用#）
# driver.find_element_by_css_selector('i#cart_num').click()
#
# .class属性值（只有class才可以使用.）
# driver.find_element_by_css_selector('div.login>a:last-child').click()
# driver.find_element_by_css_selector('div.help>a:nth-child(1)').click()
# driver.find_element_by_css_selector('input.but1)').send_keys('外套')
# 标签[属性=属性值]
# driver.find_element_by_css_selector('input[class=but1]').send_keys('1')
# driver.find_element_by_css_selector('input[id="ssx_submit"]').click()
# driver.find_element_by_css_selector('input[placeholder="请输入你要查找的关键字"]').send_keys('1')
# driver.find_element_by_css_selector("input[name=key][size='55']").send_keys('1')
# driver.find_element_by_css_selector('div[class=help]>a:first-child').click()
# driver.find_element_by_css_selector('div[class="schhot"]>a:nth-child(6)').click()
# driver.find_element_by_css_selector('form>div>input:last-child').click()
# driver.find_element_by_css_selector("div[class='schbox']>form>input:nth-child(1)").send_keys('12345')
# driver.find_element_by_css_selector("div[class='schbox']>form>input:nth-child(1)").clear()

# driver.find_element_by_css_selector('div.schhot>a:first-child').click()
# driver.find_element_by_css_selector('div.con1>a:nth-child(2)').click()
# driver.find_element_by_css_selector('div.nav_pub>a:nth-child(5)').click()


#link_text
# driver.find_element_by_link_text("男装").click()
# driver.find_element_by_link_text("荔枝").click()
# driver.find_element_by_link_text("登陆").click()
# driver.find_element_by_link_text("品牌街").click()
# driver.find_element_by_link_text("快快来呀马上就没有了").click()
#by_partial_link_text
# driver.find_element_by_partial_link_text('登').click()
# driver.find_element_by_partial_link_text('家装').click()
# driver.find_element_by_partial_link_text('9.9').click()
# driver.find_element_by_partial_link_text('男鞋').click()
# driver.find_element_by_partial_link_text('T恤').click()

#窗体操作
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# #获得title顶部网址的名字
# # a=driver.title
# # print(a)
# a=driver.current_url
# print(a)

# #刷新
# driver.refresh()

# #返回
# driver.back()

# # 前进
# driver.find_element_by_partial_link_text('9.9').click()
# driver.back()
# driver.forward()

# # 实现窗体最大化
# driver.maximize_window()


#设置窗体大小（第一个值为宽，第二个值为高）
# driver.set_window_size(1200,800)
#.clear()方法
# driver.find_element_by_css_selector("div[class='schbox']>form>input:nth-child(1)").send_keys('12345')
# driver.find_element_by_css_selector("div[class='schbox']>form>input:nth-child(1)").clear()

# .size方法,获取输入框的尺寸
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# chicun=driver.find_element_by_css_selector("div[class='schbox']>form>input:nth-child(1)").size
# print(chicun)

# # 取字典的值
# print(chicun['height'])

#.text方法 获取文本值
# aa=driver.find_element_by_xpath("//body/div[2]/div/div[2]/div[2]/a[5]").text
# print(aa)

# .get_attribute(‘属性’)
# aa=driver.find_element_by_xpath("//input[@class='but1']").get_attribute("type")
# print(aa)

#.is_displayed判断控件是否加载出来
# aa=driver.find_element_by_xpath("//input[@class='but1']").is_displayed()
# print(aa)

#get_attribute('value')拿输入后的回显
# if aa ==True:
#     driver.find_element_by_xpath("//input[@class='but1']").send_keys('袜子')
#     ee=driver.find_element_by_xpath("//input[@class='but1']").get_attribute('value')
#     print(ee)

#鼠标事件
# from selenium import webdriver
# #1.导入ActionChains模块
# from selenium.webdriver.common.action_chains import ActionChains
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
#2.先定位1级菜单的位置
# aa=driver.find_element_by_link_text("家电数码")
# #3.移动鼠标到一级菜单
# #4..perform()执行
# ActionChains(driver).move_to_element(aa).perform()
# #5.对二级菜单进行操作
# driver.find_element_by_link_text("手机").click()

# context_click（右击）
# ActionChains(driver).context_click(aa).perform()
# duble_click（双击）
# ActionChains(driver).double_click(aa).perform()

# from selenium import webdriver
# from selenium.webdriver.common.action_chains import ActionChains
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.huodongxing.com/login?ReturnUrl=%2f')
# driver.maximize_window()#实现窗体最大化

# 滑块  drag_and_drop_by_offset
# 1.定位位置
# //a[@class='geetest_logo']
# time.sleep(20)
# a=driver.find_element_by_xpath("//div[@class='geetest_radar_tip']").click()
# time.sleep(5)
# b=driver.find_element_by_xpath("//div[@class='geetest_slider_button']")
# c=driver.find_element_by_xpath("//tragetplace]")
# # ActionChains(driver).drag_and_drop_by_offset(b,100,0).perform()
#将滑块移动到固定位置
# ActionChains(driver).drag_and_drop(b,c).perform()
from selenium.webdriver.common.keys import Keys
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')
# driver.find_element_by_xpath("//input[@class='but1']").send_keys('袜子')

#键盘事件（回车和删除键）
# driver.find_element_by_xpath("//input[@class='but1']").send_keys(Keys.ENTER)
# driver.find_element_by_xpath("//input[@class='but1']").send_keys(Keys.BACK_SPACE)
#全选/剪贴/粘贴/  Keys.CONTROL,’a’/’x’/’v’
# driver.find_element_by_xpath("//input[@class='but1']").send_keys(Keys.CONTROL,'a')
# time.sleep(10)
# driver.find_element_by_xpath("//input[@class='but1']").send_keys(Keys.CONTROL,'x')
# time.sleep(10)
# driver.find_element_by_xpath("//input[@class='but1']").send_keys(Keys.CONTROL,'v')

#窗体句柄
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.baidu.com/')

#打印所有窗体信息
# print(driver.window_handles)
# driver.find_element_by_link_text("新闻").click()
# driver.find_element_by_link_text("hao123").click()
#打印所有窗体信息
# print(driver.window_handles)

#打印句柄所在的窗口信息
# print(driver.current_window_handle)#句柄仍在第一个窗体

#切换句柄所在的窗体
# driver.switch_to.window(driver.window_handles[1])

#打印当前窗体
# print(driver.current_window_handle)
# driver.close()
# time.sleep(5)
# driver.quit()
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('http://101.133.169.100/yuns/index.php')

#截图
# driver.get_screenshot_as_file("C:/Users/刘雪霏/Desktop/python/zuoye.png")
# driver.quit()
# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://mail.163.com/')
# driver.find_element_by_xpath("//input[@name='email']").send_keys("447955670")

#定位失败，显示NoSuchElementException
#定位iframe位置，如果没有id和name属性，用xpath相对路径
# aa=driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe')
# driver.switch_to.frame(aa)
# driver.find_element_by_xpath('//input[@name="email"]').send_keys(447955670)
# driver.find_element_by_name("password").send_keys('123456')

#select练习
# from selenium import webdriver
# import time
# #1.导select类
# from selenium.webdriver.support.select import Select
# driver = webdriver.Chrome()
# driver.get('https://ctrip.com/')
# #2.定位控件
# #方式1
# aa=driver.find_element_by_id('J_roomCountList')
# Select(aa).select_by_visible_text('1间')
# #方式2
# aa=driver.find_element_by_name('Star')
# Select(aa).select_by_index(2)
# time.sleep(5)
# # 方式3
# aa=driver.find_element_by_id('J_roomCountList')
# Select(aa).select_by_value("10")
# from selenium import webdriver
# import time
# from selenium.webdriver.support.select import Select
# driver = webdriver.Chrome()
# driver.get('https://ctrip.com/')
# #1.有input属性
# # js=driver.find_element_by_id('HD_CheckIn').clear()
# # js=driver.find_element_by_id('HD_CheckIn').send_keys('2022-04-20')
# # js="document.getElementById('HD_CheckIn').removeAttribute(readonly)"

# #滚动条属性
# #底部
# js="var q=document.documentElement.scrollTop=10000"
# driver.execute_script(js)
# time.sleep(5)
# #顶部
# js="var q=document.documentElement.scrollTop=0"
# driver.execute_script(js)
# time.sleep(5)
# #scrollBy 偏移多少
# driver.execute_script("window.scrollBy(0,200)")
# time.sleep(5)
# #scrollTo 偏移到多少
# driver.execute_script("window.scrollTo(0,700)")
# time.sleep(5)
# #滚动到页面的一半
# driver.execute_script("window.scrollTo(0,document.body.scrollHeight*0.5)")
# time.sleep(5)
